package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ZS_PROJECT_SEARCH_WHERE_IS_ENEMY, desc = "搜索对手在哪里")
public class ZsProjectSearchWhereIsEnemyCmd extends AbstractCommand {

    private long searchUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsProjectSearchEnemyWhereReqMsg reqMsg = ZhaoShangProto.ZsProjectSearchEnemyWhereReqMsg.parseFrom(packet.getBytes());
        searchUserId = reqMsg.getUserId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.ZhaoShang.getValue())) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if (!ZsMgr.isZsSystemOpenTime()) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        //直接上跨服查找
        ZhaoShangProto.ZsProjectSearchEnemyWhereReqMsg.Builder crossReqMsg = ZhaoShangProto.ZsProjectSearchEnemyWhereReqMsg.newBuilder();
        crossReqMsg.setUserId(searchUserId);
        player.sendPacket(CrossProtocol.C2_ZHAO_SHANG_PROJECT_SEARCH_WHERE, crossReqMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ZhaoShangProto.ZsProjectSearchEnemyWhereRespMsg.Builder respMsg = ZhaoShangProto.ZsProjectSearchEnemyWhereRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_ZS_PROJECT_SEARCH_WHERE_IS_ENEMY, respMsg);
        }
    }
}
